// Voxel.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "Voxel.h"
#include <gl\gl.h>
#include <gl\glu.h>
#include "Utility_wrap.h"


Voxel::VoxelObj::VoxelObj()
{
}

Voxel::VoxelObj::~VoxelObj()
{

}

void Voxel::VoxelObj::draw(int mode)
{
	for (size_t i = 0; i < m_cubes.size(); i++)
	{
		m_cubes[i]->draw(mode);
	}
}

void Voxel::VoxelObj::loadVoxelFromFile(char* filePath)
{
	// Generate point cloud data
	FILE* f = fopen(filePath, "r");
	ASSERT(f);

	int nbPoint = 0;
	fscanf(f, "%f\n", &m_voxelSize);
	fscanf(f, "%d\n", &nbPoint);

	for (size_t i = 0; i < nbPoint; i++)
	{
		float x,y,z;
		fscanf(f, "%f %f %f\n", &x, &y, &z);
		Vec3f ptf(x,y,z);
		CubePtr newCube(new Cube(ptf, m_voxelSize));
		m_cubes.push_back(newCube);
	}

	fclose(f);
}
